
// 代码编辑器
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')

const path = require("path");
function resolve(dir) {
    return path.join(__dirname, dir);
}
module.exports = {
    pages: {
        index: {
            entry: "src/main.ts",
            template: "public/index.html",
            filename: "index.html"
        }
    },
    assetsDir: "static",
    productionSourceMap: false,
    runtimeCompiler: true,
    chainWebpack: (config) => {

        // 生产环境下屏蔽公共依赖
        if(process.env.NODE_ENV === 'production') {
            config.externals({
                vue: "vue"
            })
        }

        // 扩展 webpack 配置，使 components 目录 加入编译
        config.module
            .rule("js")
            .include.add(path.resolve(__dirname, "components"))
            .end()
            .use("babel")
            .loader("babel-loader")
            .tap(options => {
                return options;
            });

        // 添加别名
        config.resolve.alias
            .set("@", resolve("src"))

        config.module
            .rule("eslint")
            .use("eslint-loader")
            .loader("eslint-loader")
            .tap((options) => {
                options.fix = true;
                return options;
            });

    },
    configureWebpack: (config) => {
        config.plugins.push(
            new MonacoWebpackPlugin({
                // available options are documented at https://github.com/Microsoft/monaco-editor-webpack-plugin#options
                languages: ['javascript', 'css', 'html', 'typescript', 'json']
            })
        );

    },
};
